
\section{Context}
\label{sec:context}

% Breve introdução
This section explains with more details each technique studied. A small
use case example is firstly introduced in order to explain how ad hoc
tests are currently created and executed in practice. Then, we discuss how this
same example would be tested by using a model-based approach with TaRGeT.


\subsection{Use Case Example}
\label{sub-sec:uc-example}

% Introduz exemplo do projeto
For the next two subsections, consider the following fictional use case:
{\it Subscribe Person}, in which an official of a library registers students.
In the main flow, the user provides the person data,
with a valid national registration ID. Then, the system validates the filled
form, checks if the ID is valid, and if the ID is already enrolled in the
database. If the ID is not in the database, the system presents an empty form
to be filled, otherwise the system presents the form with person's data for
edition. Exception flows cover scenarios which the form is not filled correctly
or when the ID is not valid. Such scenarios are described as follows:


\begin{itemize}
  \item Main Flow: Subscribe Person
  \begin{enumerate}
    \item User enters person's ID;
    \item System validates person's ID;
    \item System exhibits subscribers' form;
    \item User fills form;
    \item User clicks subscribe button;
    \item System validates data and subscribes person.
  \end{enumerate}
  
  \item Alternative Flow: ID already registered in the database
\begin{enumerate}
    \item It starts on step 2 of Main Flow if user entered an ID already
     registered in the database;
    \item System alerts that the ID is already in the database;
    \item System presents filled form with person's data for edition;
    \item User updates persons' data;    
    \item Flow returns to step 5 of Main Flow.
  \end{enumerate}
  
  \item Exception Flow: Invalid ID
  \begin{enumerate}
    \item It starts on step 2 of Main Flow if user entered an invalid ID;
    \item System highlights user's ID field, presenting an invalid ID message;
    \item Flow returns to step 1 of Main Flow.
  \end{enumerate}
\end{itemize}


\renewcommand{\tablename}{Listing}

\scriptsize
\begin{table}[!t]
\renewcommand{\arraystretch}{1.3}
\caption{Sample TaRGeT modeling}
\label{tbl:target-model}
\centering
\begin{tabular}{l}
\hline
\textless useCase\textgreater \\
~~\textless id\textgreater UC01\textless /id\textgreater \\
~~\textless name\textgreater Subscribe Person\textless /name\textgreater \\
~~\textless setup\textgreater User is logged in and selected Subscribe Person menu\textless /setup\textgreater \\
~~\textless flow\textgreater \\
~~~~\textless description\textgreater Main flow\textless /description\textgreater \\
~~~~\textless fromSteps\textgreater START\textless /fromSteps\textgreater \\
~~~~\textless toSteps\textgreater END\textless /toSteps\textgreater \\
~~~~\textless step\textgreater \\
~~~~~~\textless stepId\textgreater 1A\textless/stepId\textgreater \\
~~~~~~\textless action\textgreater User enters person's ID\textless /action\textgreater \\
~~~~~~\textless response\textgreater System validates person's ID\textless /response\textgreater \\
~~~~\textless /step\textgreater \\
~~~~~~~~...\\
~~\textless /flow\textgreater \\
\textless /useCase\textgreater \\

\hline
\end{tabular}
\end{table}
\normalsize

% Exemplo de teste manual
\subsection{Manually generated tests}
\label{sub-sec:manual-tests}

% Descreve combinação dos cenários ad hoc
Referring to the use case example in Section~\ref{sub-sec:uc-example}, 
consider a test suite manually generated for this use case. 
% De quem é a tarefa
Consider also two different system testers, with different background skills,
assigned to generate this test suite in an ad hoc way.
% Primeiro testador 
An inexperienced tester could generate a test suite with only three scenarios:
one checking the main flow; one for the alternative flow and then; and one for
the exception flow. Unfortunately, the first tester did not investigated 
the relationship between the exception flow and the alternative flow. Therefore,
the generated test suite has unverified scenarios.

% Segundo testador 
In addition to the previously described scenarios, a second (experienced) tester
could consider a scenario in which the association of the exception flow and the
alternative flow are verified.
% Conclusao
Thus, different test suites could be generated according to testers'
skills and knowledge of the SUT.
If the test suite does not have the right details and flows, this could lead to
undetected defects. For instance, the exception flow does not explicitly
describe if it can either return to the main flow or alternative flow.
Hence, the association of the exception flow and the alternative flow is a
complex scenario.

% Descreve vantagens ad hoc
Despite the fact that different test suites could be generated, ad hoc tests
have some flexibility. 
For instance, if the documentation is not precise enough, experienced testers
could also consider scenarios difficult to foresee. 
% Cenário
Suppose that after the ID validation, the user could go back to
the previous page and enter a new ID.
In such scenario, consider that the subscribers' form is filled with person's
data  according to the alternative edition flow. Then, the user goes back
and enter a new ID.
% Possibilidades
What would happen in such scenario? Would the subscribers' form be a new one or would it
have unwanted data from the previously entered ID?


% Exemplo de teste com o TaRGeT
\subsection{Model-based generated tests}
\label{sub-sec:target-tests}

In order to automatically generate test suites, there are many different
model-based testing tools which guide the test generation process. 
Among these tools, TaRGeT emerges as a promising
tool, providing features such as automatic generation of test suites from use case
scenarios, use of a Controlled Natural Language (CNL), and test case
selection. Thus, TaRGeT was chosen as the model-based tool of this study.

% Descreve modelagem com o TaRGeT
Considering a MBT strategy with TaRGeT, the use case described in
Section~\ref{sub-sec:uc-example} would be transcripted into a model. 
% Descreve a modelagem
The modeling activity consist on receiving a use case document and translating
it to a readable format for the tool, such as a XML~\cite{xml10fifth} schema,
structuring possible flows and actions. 

The model states the main flow, the alternative flows and also
the exception flows. In each flow, it declares where the flow starts and where
it ends. 
In order to describe the scenarios, the model would also declare what are the pre/post
conditions before and after the tests execution. For instance,
Listing~\ref{tbl:target-model} presents an excerpt of subscribe person's use
case XML model. The markup language used for modeling is very intuitive and can be
easily written and read.

% Descreve geracao de cenários com o TaRGeT 
After the modeling, the TaRGeT would generate a test suite with all the
main scenarios and also scenarios with possible combinations of flows, which
are generated from the interaction of different scenarios. The test suite generation uses an
algorithm that combines the interaction of possible flows, eliminating similar
test cases. For the described use case, the tool would generate four
scenarios: one for each declared flow, and also one combining the exception and
alternative flow. For instance, Table~\ref{tbl:target-output} presents TaRGeT output for the main flow.

\renewcommand{\tablename}{Table}
\setcounter{table}{0}

\begin{table}[!t]
\caption{Sample TaRGeT generated script}
\label{tbl:target-output}
\centering
\begin{tabular}{c|c|c}
\hline
\bfseries Pre & \multicolumn{2}{l}{User is logged in and selected Subscribe
Person menu} \\
\hline\hline
\bfseries & \bfseries Action & \bfseries Response\\
\hline\hline
\bfseries 1 & User enters person's ID & System validates person's ID\\
\hline
\bfseries 2 & - & System exhibits subscriber's form\\
\hline
\bfseries 3 & User fills form & -\\
\hline
\bfseries 4 & User clicks subscribe & System validates data\\
\hline
\bfseries 5 & - & System subscribes person\\
\hline
\hline
\bfseries Post & \multicolumn{2}{l}{Person's ID is registered on 
database}
\\
\hline
\end{tabular}
\end{table}

TaRGeT generated tests are documented and reusable artifacts. The task of
generating a test suite is automated and the generated scenarios derive from the system model.
Hence, new project members can test scenarios previously modeled. Also, the
modeling activity helps validating requirements specification and facilitates systems
comprehension. On the other hand, manually generated tests are strictly related
with testers' experience. The task of generating a test suite is manual and
centered only on the tester, being a laborious, time consuming, and error
prone task.
